package com.qinhailin.portal.dbm.managectrl;

import com.jfinal.aop.Inject;
import com.jfinal.plugin.activerecord.Record;
import com.qinhailin.common.base.BaseController;
import com.qinhailin.common.routes.ControllerBind;
import com.qinhailin.common.vo.Feedback;
import com.qinhailin.portal.dbm.model.DTContact;
import com.qinhailin.portal.dbm.service.DTContactServiceImpl;

/**
 * 联系人
 * @author ward
 */
@ControllerBind(path="/portal/dbm/contact")
public class ContactController extends BaseController{
	
	//@Inject
	//CTCustomerServiceImpl service;
	//@Inject
	//CPGetIDService idService;
	//@Inject
	//DTSystemdataServiceImpl systemdataService;
	
	@Inject
	DTContactServiceImpl service;
	
	
	public void index() {
		this.render("index.html");
	}
	
	public void list() {
		Record record = new Record();
		record.set("rCust_ID", getPara("rCustID"));
		record.set("xName", getPara("xName"));
		record.set("xCustName", getPara("xCustName"));
		renderJson(service.page(getParaToInt("pageNumber", 1), getParaToInt("pageSize", 10), record));
	}
	
	public void delete() {
		service.deleteByIds(getIds());
		renderJson(Feedback.success());
	}
	
	public void add() {
		this.render("add.html");
	}
	
	public void save() {
		//CTCustomer customer = this.getModel(CTCustomer.class);
		DTContact contact = this.getBean(DTContact.class);		
		if(!service.save(contact)) {
			setException("保存失败");
		}
		render("add.html");
	}
	
	
	public void update() {
		DTContact contact = this.getBean(DTContact.class);
		
		if(!service.update(contact)) {
			setException("保存失败");
		}
		render("edit.html");
	}
	
	public void edit() {
		DTContact contact = service.findByID(this.getInt());
		setAttr("contact", contact);
		render("edit.html");
	}
	

}
